#ifdef ARRAY_H
#define ARRAY_H
#include<iostream>
#include<cstdlib>
using namespace std;

enum ErrorType
{invalidArraySize, memoryAllocationError,indexOutOfRange};

char * errorMsg=
{
		"invalid array size",
		"memory allocat error",
		"invalid index"
};

template <class T>

class Array
{
	
	private:
			int size;
			T *list;
			void errorFun(ErrorType et) const;

	public:
			Array(int sz=50);
			Array(const Array <T> & a);
			~Array();
			Array<T> & operator = (const Array<T> & rhs);
			T& operator [] (int index);
			operator T* (void) const;
			int getSize();
			int resize(int sz);
			void display();




};


template<class T>
void Array<T>::errorMsg(ErrorType et)
{
		cout<<errorMsg[et]<<endl;
		cout<<endl;
		exit(1);
}


template<class T>
Array<T>::Array(int sz)
{
		if (sz<=0)
			errorFun(invalidArraySize);
		size=sz;
		list=new T[size];
		if(list=NULL)
				errorFun(memoryAllocationError);
}

template<class T>
Array<T>::Array(const Array<T> & rhs)
{
		size=rhs.size;
		list=new T[size];
		if(list=NULL)
				errorFun(memoryAllocationError);
		for(int i=0;i<size;i++)
				list[i]=rhs[i];

}

template<class T>
Array<T>::~Array()
{
		delete list;
}



template<class T>
T& Array<T>::operator [] (int index)
{
		if(index<0 || index>size)
				errorFun(indexOutOfRange);
		else
				return list[index];
}


template<class T>
T& Array<T>::operator =(Array<T> & rhs)
{

		if(size!=rhs.size)
		{
				delete list;
				size=rhs.size;
				list=new T[size];
				if(list=NULL)
						errorFun(memoryAllocationError);
		}
		for(int i=0;i<size;i++)
				list[i]=rhs[i];
		return *this;

}

template<class T>
Array<T>::operator T* () const
{
	return list;
}

 
template<class T>
int Array<T>::getSize()
{
		return size;
}


template<class T>
int Array<T>::resize(int sz)
{
		int ret=0;
		if (sz<0)
				errorFun(invalidArraySize);
		if(sz==size)
				return 0;
		T * newlist=new T[sz];
		if(newlist=NULL)
				errorFun(memoryAllocationError);
		int n= size<sz?size:sz;
		for(int i=0;i<n;i++)
				newlist[i]=list[i];
		delete list;
		list=newlist;
		size=sz;
}

		
		
#endif
